<?php
namespace app\agent\controller;
use app\agent\controller\BaseController;
class IndexController extends BaseController {

	public function index() {
		$where['id'] = session('agent_id');
		$data = select_data('agent',$where);
		$this->assign('data',$data);
		return $this->fetch();
	}
	public function info() {
		$param['id'] = session('agent_id');
		if(request()->isPost()){
			$param=input('post.');
			unset($param['file']);
			$res = db('agent')->update($param);
			if($res){
				return json(['code'=>200,'msg'=>'修改成功']);
			}else{
				return json(['code'=>402,'msg'=>'修改失败']);
			}
			
		}
		$this->assign('data',db('agent')->find($param['id']));
		return $this->fetch();
	}
	public function verif() {
		if(request()->isPost()){
			$param=input('post.');
			$param['agent_id'] = session('agent_id');
			$param['status'] = 1;
			$param['add_time'] = now_time();
			
			if($param['id']>0){
				$resutl = db('agent_verif')->update($param);
			}else{
				$resutl = db('agent_verif')->insert($param);
			}
			if($resutl){
				//更新认证状态
				$rest1 = db('agent')->where('id',session('agent_id'))->update(['is_verify'=>3]);
				
				return json(['code'=>200,'msg'=>'提交成功']);
			}else{
				return json(['code'=>402,'msg'=>'提交失败']);
			}
		}
		$this->assign('data',db('agent_verif')->where('agent_id',session('agent_id'))->find());
		
		return $this->fetch();
	}
	
	function get_verif(){
		$user_verif = db('agent_verif')->where('agent_id',session('agent_id'))->find();
		if($user_verif['status'] != 2){
			return  json(["code"=>403]);
		}else{
			return  json(["code"=>200]);
		}
		
	}
	
}
